library Wave15c initializer init requires LegacySystem


    /*
    Player 11: USMC. Nadav
    set udg_ShivaTaken = false //Used for TacNuke Deployment success
    udg_BlackHawk = CWO Nadav
    udg_InfantryGroup[1] = 4 Marines from Extraction Helo
    Titan TacNuke - I01A

    TacNuke Locations
    Airfield
    PowerGenerator
    Town
    Home7 //Windmill

    */
    
    
    //udg_EMSphere = Aviation Fuel count proxy


	
	private function HavokInvi takes nothing returns nothing
		call UnitAddAbility(udg_Boss,'A05W') //Invisibility - Delta Camo
		call PolledWait(GetRandomReal(5.0,30.0))
		call UnitRemoveAbility(udg_Boss,'A05W')
	endfunction

	private function ContainmentSpawn takes nothing returns nothing
		if (GetPlayerState(Player(13), PLAYER_STATE_RESOURCE_FOOD_USED)<80 and GetPlayerState(Player(14), PLAYER_STATE_RESOURCE_FOOD_USED)<80) then
			call RandomSpawn('n00A',1,GetRandomInt(0,IMaxBJ(3,udg_Spawn) )) //Tartarus
			call GankMarine(Player(13),'n004',2*udg_Spawn,1000,1800) //Zombie #2
			call RandomSpawn('u005',3,GetRandomInt(0,udg_Spawn)) //Gargolye #2
			call RandomSpawn('u00U',2,GetRandomInt(0,udg_Spawn)) //Poppers
			call RandomSpawn('n001',3,GetRandomInt(0,2)) //Immortal #2
		endif
		
		call SpawnShredder()
		call TriggerSleepAction(GetRandomReal(0.0,15.0))
		call LightningAmbience.execute()
		if udg_SquadXP>75000 and GetRandomInt(0,5)==1 and udg_CurrentWave >= 16 then
			call HavokInvi.execute()
		elseif udg_SquadXP>60000 and GetRandomInt(0,1)==1 then
			call GankMarine(Player(13),'n016',udg_Spawn,1000,1800) //Invisible Worm for Infection
		endif
		call GankMarine(Player(13),'n00M',udg_Spawn+2,1500,2500) //Hasted Variant
	endfunction

	globals
		private integer udg_number = 0
		private trigger ContainmentSpawnTrigger = null 
	endglobals
	
	private function SetContainmentSpawnEnabled takes boolean b returns nothing 
		if b then
			call EnableTrigger(ContainmentSpawnTrigger)
		else
			call DisableTrigger(ContainmentSpawnTrigger)
		endif
	endfunction
	
    private function AviationFuelConditions takes nothing returns boolean
        return GetSpellAbilityId()=='A08D' //Deploy Aviation Fuel
    endfunction

    private function AviationFuel takes nothing returns nothing
        local integer i = 1
        local unit u = GetTriggerUnit()
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local real dx = GetUnitX(udg_BlackHawk) - x
        local real dy = GetUnitY(udg_BlackHawk) - y
        if dx*dx+dy*dy<=160000.0 then //400 distance
            call AttachSoundToUnit(gg_snd_FuelSynthesizer, udg_BlackHawk)
            call SetSoundVolume(gg_snd_FuelSynthesizer, 127)
            call StartSound(gg_snd_FuelSynthesizer)
            call RemoveItem(GetUnitItem(u,'I019'))
            set udg_number = udg_number + 1
            if udg_number==1 then
                call DisplayTimedTextToPlayer( GetLocalPlayer(), 0.0, 0.0, 10.0, "1 can of Aviation Fuel filled." )
            elseif udg_number<udg_FuelRequirement then
                call DisplayTimedTextToPlayer( GetLocalPlayer(), 0.0, 0.0, 10.0, I2S(udg_number) + " cans of Aviation Fuel filled." )
            elseif udg_number>=udg_FuelRequirement and GetWidgetLife(udg_BlackHawk)>0.405 then
                call DestroyTrigger(GetTriggeringTrigger())
                call UnitAddAbility(udg_BlackHawk,'Avul')
                call PauseUnit(udg_BlackHawk,false)
                call MBSet( udg_SquadStatus, 1, 1, "Objective Completed : Black Hawk Refueled" )
                call ALICE2Text(10.0, "Black Hawk restored. |cff1e90ff50 XP|r awarded to all Marines." )
                loop
                    exitwhen i>udg_InitialPlayers
                    if GetPlayerSlotState(ConvertedPlayer(udg_Sorted[i]))!=PLAYER_SLOT_STATE_LEFT then
                        set udg_Experience[udg_Sorted[i]] = udg_Experience[udg_Sorted[i]] + 50
                    endif
                    set i=i+1
                endloop
            endif
        endif
        set u = null
    endfunction

    private function FuelDeployment takes nothing returns nothing
        local integer i=1
        local trigger t = CreateTrigger()

        
        call TriggerAddCondition(t,Condition(function AviationFuelConditions))
        call TriggerAddAction(t,function AviationFuel)

        loop
            exitwhen i>udg_InitialPlayers
            call TriggerRegisterPlayerUnitEvent(t, ConvertedPlayer(udg_Sorted[i]), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i=i+1
        endloop
					
        //North Hangar
        call CreateItem('I019',11837.0,9658.0) //Aviation Fuel
        call TriggerSleepAction(0.)
        call CreateItem('I019',12004.0,9512.0)
        call TriggerSleepAction(0.)
        //West Hangar
        call CreateItem('I019',12608.0,7006.0)
        call TriggerSleepAction(0.)
        call CreateItem('I019',12402.0,7120.0)
        call TriggerSleepAction(0.)
        //East Hangar
        call CreateItem('I019',13643.0,8290.0)
        call TriggerSleepAction(0.)
        call CreateItem('I019',13762.0,8191.0)
    endfunction

    private function NadavLanding takes nothing returns nothing
        local integer i = 1
        local integer id
        local integer itemid = 0
        local real angle
        local unit u
        local real x = GetLocationX(udg_LZPoint)
        local real y = GetLocationY(udg_LZPoint)
        local real theta = GetRandomReal(0.0,6.28)
        local real ux = Clamp(x+3000.0*Cos(theta),GetRectMinX(bj_mapInitialPlayableArea),GetRectMaxX(bj_mapInitialPlayableArea))
        local real uy = Clamp(y+3000.0*Sin(theta),GetRectMinY(bj_mapInitialPlayableArea),GetRectMaxY(bj_mapInitialPlayableArea))
        set udg_BlackHawk = CreateUnit(Player(11),'h00Q',ux,uy,theta+3.14)
        call SetForceAllianceStateBJ( bj_FORCE_PLAYER[9], udg_UnknownEntities, bj_ALLIANCE_ALLIED )
        call SetUnitScalePercent(udg_BlackHawk,50.0,50.0,50.0)
        call RemoveGuardPosition(udg_BlackHawk)
        call TriggerSleepAction(0.)
        call IssuePointOrder(udg_BlackHawk,"move",x,y)
        call StartSound(gg_snd_BlackHawkRotor)
        set u = CreateUnit(Player(14),'n00P',x,y,0.0) //DangerZone Dummy
        call UnitApplyTimedLife(u,'Bhwd',9.0)
        call PolledWait(2.25)
        call StartSound(gg_snd_BlackHawk)
        call PolledWait(3.25)
        call SetUnitFlyHeight(udg_BlackHawk,15.0,130.0)
        call SmoothUnitResize(udg_BlackHawk,1.45,1.55,4)
        call SetLandingAreaWindEnabled(true)
        call PolledWait(3.)
        call SetUnitTimeScalePercent(udg_BlackHawk,65.0)
        call HeloShock(udg_BlackHawk)
        call BlackHawkWashOff.execute()
        call PlaySoundAtPointBJ(gg_snd_BlackHawkLand,100.0,udg_LZPoint,15.0)
        call PolledWait(2.5)
        call KiloEvac(udg_BlackHawk)
        loop
            exitwhen i>4
            set angle = 360.0*(I2R(i)-1)/I2R(4)
            if GetRandomInt(0,12)==1 then
                set id = 'z00E' //IUL
            elseif GetRandomInt(0,12)==1 then
                set id = 'z00G' //Sniper
            elseif GetRandomInt(0,4)==1 then
                set id = 'z009' //Flamethrower
                set itemid = 'I003' //Hecate
            elseif GetRandomInt(0,6)==1 then
                set id = 'z001' //Corpsman
                set itemid = 'I00A' //Blastocyst
            elseif GetRandomInt(0,10)==1 then
                set id = 'z004' //Engineer
                set itemid = 'I00W' //Flare Gun
            elseif GetRandomInt(0,3)==1 then
                set id = 'z000' //Machine Gunner
                set itemid = 'I002' //AP
            elseif GetRandomInt(0,5)==1 then
                set id = 'z00F' //Marksman
            else
                set id = 'z008' //Rifleman
                set itemid = 'I002' //AP
            endif
            set u = CreateUnit(ConvertedPlayer(11),id,x+80.0,y-175.0,0.0)
            call GroupAddUnitSimple(u,udg_InfantryGroup[1])
            call SetLoadState(I2S(GetHandleId(u)),1)
            call UnitAddItemById(u,'I004') //Medkit
            call UnitAddItemById(u,'I001') //Composite
            if itemid!=0 then
                call UnitAddItemById(u,itemid)
                set itemid = 0
            endif
            if id=='z001' then
                //call TriggerRegisterUnitEvent(gg_trg_Anti_Venom,u,EVENT_UNIT_SPELL_EFFECT)
            elseif id=='z006' then
                //call TriggerRegisterUnitEvent(gg_trg_Control_Aircraft,u,EVENT_UNIT_SPELL_EFFECT)
            elseif id=='z004' then
               // call TriggerRegisterUnitEvent(gg_trg_Nanosteel_Net,u,EVENT_UNIT_SPELL_EFFECT)
            endif
            call RegisterUnitForAilmentChecks(u)
            //call TriggerRegisterUnitEvent(gg_trg_Article_15,u,EVENT_UNIT_DEATH)
            call IssuePointOrder(u,"attack",x+(325.0*Cos(angle*0.01745)),y+(325.0*Sin(angle*0.01745)))
            if GetRandomInt(0,1)==1 then
                call TriggerSleepAction(0.)
            endif
            set i=i+1
        endloop
		set udg_soundpath = "war3mapImported\\LockAndLoad.wav"
		call PlaySoundPath.execute()
        //call StartSound(gg_snd_RockandRoll)
        call KiloEvac(udg_BlackHawk)
        call PolledWait(2.)
        call SetLandingAreaWindEnabled(false)
        call PauseUnit(udg_BlackHawk,true)
        call EnumDestructablesInCircleBJ(600,udg_LZPoint,function TreeShakeEnd)
        call PolledWait(3.)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9],udg_UnknownEntities,bj_ALLIANCE_UNALLIED)
        call PolledWait(1.)
        set u = null
    endfunction

    private function Wave15c takes nothing returns nothing
        local real x
        local real y
        local integer i = 1
        local real trans = 0.0
        
        if udg_Players<1 or udg_Chapter==3 then
            return
        endif
        if GetRandomInt(0,10)==1 then
            set trans = 40.0
        endif
		
		if ContainmentSpawnTrigger == null then
			set ContainmentSpawnTrigger = CreateTrigger()
			call DisableTrigger(ContainmentSpawnTrigger)
			call TriggerRegisterTimerEventPeriodic(ContainmentSpawnTrigger,59.0*udg_Pace)
			call TriggerAddAction(ContainmentSpawnTrigger, function ContainmentSpawn)
		endif
		
        set udg_Chapter = 3
        set udg_Intermission = true
        set udg_XPFactor = udg_XPFactor*1.2
        set udg_Lighting = true
        call SquadRatingCalc.execute()
        call putBoolean(null,"NukeSuccess",false) //Used for TacNuke Deployment success
        set udg_MarineSpawnArea[1] = gg_rct_CaravanEnd
        set udg_MarineSpawnArea[2] = gg_rct_South_Road
        set udg_MarineSpawnArea[3] = gg_rct_CaravanCEnd
        set udg_MarineSpawnArea[4] = gg_rct_West_Road
        set udg_MarineStagingArea[1] = gg_rct_TownEntranceNorth
        set udg_MarineStagingArea[2] = gg_rct_TownEntranceSouth
        set udg_MarineStagingArea[3] = gg_rct_TownEntranceEast
        set udg_MarineStagingArea[4] = gg_rct_TownEntranceWest
        set udg_LZNames[0] = "Alpha"
        set udg_LZNames[1] = "Bravo"
        set udg_LZNames[2] = "Charlie"
        set udg_LZNames[3] = "Delta"
        set udg_LZNames[4] = "Epsilon"
        set udg_LZNames[5] = "Gamma"
        set udg_ReloadText = 30
        set udg_Immortal = 'n001'
        set udg_Ghoul = 'u003'
        set udg_Parasite = 'n00J'
        call PauseAllUnitsBJ(true)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 1.0, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, trans )
        call ShowInterface(false,1.0)
        call ClearTextMessages()
        call PolledWait(1.5)
        call StartSound(gg_snd_Message)
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, "                                                                             |cff8b864eContainment|r" )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " " )
        call PauseAllUnitsBJ(true)
        call PolledWait(5.5)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, 1.0, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, trans )
        call ShowInterface(true,1.0)
        call ClearTextMessages()
        set udg_Lighting = false
        call PolledWait(1.)
        set udg_Intermission = false
        call PauseAllUnitsBJ(false)
        call IntermissionRestore.execute()
        call PolledWait(5.)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 0.001, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0 )
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, 0.001, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0 )
        call TriggerSleepAction(0.)
        call IntermissionRestore()
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[11],udg_EchoCasualties,bj_ALLIANCE_ALLIED_VISION)
        call SetImmortalSpawnEnabled(true)
        call SetCrepitusSpawnEnabled(true)
        call SetGhoulSpawnEnabled(true)
        call SetDynamicEvasionEnabled(true)
        if udg_Mode==4 and udg_Players>0 then
            call ALICEText(10.0, "Chapter 2 Complete. |cff1e90ff100 XP|r awarded to " + GetPlayerName(ConvertedPlayer(udg_Sorted[1])) )
            set udg_Experience[udg_Sorted[1]] = udg_Experience[udg_Sorted[1]] + 100
        endif
		
		call DisableRareItemDropsOnDeath(Player(9))
		call DisableRareItemDropsOnDeath(Player(11))
        loop
            exitwhen i>udg_InitialPlayers
			call DisableRareItemDropsOnDeath(ConvertedPlayer(udg_Sorted[i]))
            set i=i+1
        endloop

        set i = 0
        set udg_number = 0
        set udg_ZStart = 900
        set udg_ZEnd = 2775
        call FogTransition(0.1)
        set udg_CurrentWave = 15
        call GenericActions.execute()
        call PlatoonReinforcements.execute()
        call C130Wave15.execute()
        call SetPopperExplosionControlEnabled(true)
        call PolledWait(5.)
        call PolledWait(10.)
        call GeneralText(10.0, "|cffcd950cBattalion|r : Echo Company, prepare for extraction. We're going to pull you out of there and nuke that place to hell. We can't risk an outbreak." )
        call SetContainmentSpawnEnabled(true)
        call PolledWait(10.)
        call C130Wave15.execute()
        set i = GetRandomInt(1,8)
        set x = GetRectCenterX(udg_LandingZones[i])
        set y = GetRectCenterY(udg_LandingZones[i])
        set udg_LZPoint = Location(x,y)
        call StartSound(gg_snd_SatelliteImaging)
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 3.0, "|cffcd950cALICE|r : Satellite image of Extraction Point captured." )
        call PingMinimapEx(x,y,10.0,255,0,0,false)
        call SetCameraQuickPosition(x,y)
        call PolledWait(20.)
        call GeneralText(10.0, "|cffcd950cCWO Nadav|r : I'm your pilot for tonight and I'm approaching the LZ." )
        call PolledWait(30.)
        call NadavLanding.execute()
        call PolledWait(10.)
        set i=1
        loop
            exitwhen i>udg_Players
            call CreateItem('I00I',x+GetRandomReal(-300.0,300.0),y+GetRandomReal(-300.0,300.0)) //SMAW
            call TriggerSleepAction(0.)
            set i=i+1
        endloop
        if udg_Players<3 then
            set udg_FuelRequirement=2
        elseif udg_Players>6 then
            set udg_FuelRequirement=6
        endif
        call GeneralText(15.0, "|cffcd950cCWO Nadav|r : Evac in 10 minutes. Make your way down to Jefferson Airbase and pick up " + I2S(udg_FuelRequirement) + " cans of fuel. We had a leak en route. We've patched it up...now we need fuel to get back." )
        call FuelDeployment.execute()
        call PolledWait(8.*udg_Pace)
        call MBSet( udg_SquadStatus, 1, 1, "Objective : Retrieve Aviation Fuel and Refuel Black Hawk" )
        call QuestSetDescription(udg_CurrentOrders, "Retrieve Aviation Fuel and Refuel Black Hawk." )
        call ALICE2Text(5.0, "|cff8b864eNew Objective|r : Retrieve Aviation Fuel and Refuel Black Hawk." )
        call MissionUpdate.execute()
        call PolledWait(90.*udg_Pace)
        if udg_Players>0 then
            call ExecuteRegisteredFunction("Wave16c")
            //call Wave16c.execute()
        endif
    endfunction


	private function CleanupWave takes nothing returns nothing
		call SetContainmentSpawnEnabled(false)
	endfunction
	
    private function init takes nothing returns nothing
        call RegisterFunction("Wave15c", function Wave15c)
		call RegisterFunction("Wave15c.cleanup", function CleanupWave)
    endfunction
    

endlibrary